//package com.mp.api;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.baidu.aip.ocr.AipOcr;
//import org.apache.commons.httpclient.Cookie;
//import org.apache.commons.httpclient.HttpClient;
//import org.apache.commons.httpclient.NameValuePair;
//import org.apache.commons.httpclient.cookie.CookiePolicy;
//import org.apache.commons.httpclient.methods.GetMethod;
//import org.apache.commons.httpclient.methods.PostMethod;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.http.client.params.ClientPNames;
//
//import org.json.JSONObject;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.util.HashMap;
//
///**
// * @author jack
// * @data 2019-08-20 19:14
// */
//@RestController
//@RequestMapping("/api/sg")
//public class SgApi {
//    private static final String SG_URL = "https://5535393761-rrl.cp168.ws/";
//
//
//
//    //设置APPID/AK/SK
//    public static final String APP_ID = "17055246";
//    public static final String API_KEY = "nGl3pA98EK84TooDktMLet3g";
//    public static final String SECRET_KEY = "yo7WvbGnGbPGo7BId1wP6SrSTZywQORW";
//
//    private String cookie = "ssid1=95e6b568010bc33d8723c48bfc7ff2ca; random=2481; 2a29530a2306=46416ca85d10469b";
//
//    private String code = "";
//
//
//    /**
//     * 获取游戏赔率
//     * @param
//     * @return
//     * @throws IOException
//     */
//    @GetMapping("/odds")
//    public Object odds(@RequestParam(defaultValue = "XYFT") String lottery,
//                       @RequestParam(defaultValue = "DX1,DX2,DX3,DX4,DX5,DX6,DX7,DX8,DX9,DX10,DS1,DS2,DS3,DS4,DS5,DS6,DS7,DS8,DS9,DS10,GDX,GDS,LH1,LH2,LH3,LH4,LH5") String games) throws IOException {
//        String accountUrl = "https://5535393761-rrl.cp168.ws/member/odds?lottery=XYFT&games=" + games +"&_=" + System.currentTimeMillis();
//
//        String result = doGet(accountUrl).getResponseBodyAsString();
//        return result;
//
//
//    }
//
//
//
//    @GetMapping("/bet")
//    public Object bet(HttpServletRequest request) throws IOException {
//        String accountUrl = "https://5535393761-rrl.cp168.ws/member/bet";
//        PostMethod postMethod = new PostMethod(accountUrl);
//        HttpClient httpClient = new HttpClient();
//        // 设置登陆时要求的信息，用户名和密码
//        NameValuePair[] data = { new NameValuePair("loginName", "chzeze123"), new NameValuePair("loginPasswd", "**") };
//        postMethod.setRequestBody(data);
//        // 设置 HttpClient 接收 Cookie,用与浏览器一样的策略
//        httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
//        GetMethod getMethod = new GetMethod(accountUrl);
//        // 每次访问需授权的网址时需带上前面的 cookie 作为通行证
//        getMethod.setRequestHeader("cookie", cookie);
//        httpClient.executeMethod(getMethod);
//        // 打印出返回数据，检验一下是否成功
//        String text = getMethod.getResponseBodyAsString();
//        System.out.println(text);
//          return text;
//
//    }
//
//
//
//    @GetMapping("/account")
//    public Object account(HttpServletRequest request) throws IOException {
//        String accountUrl = "https://5535393761-rrl.cp168.ws/member/accounts?_=" + System.currentTimeMillis();
//
//        String result = doGet(accountUrl).getResponseBodyAsString();
//        return result;
//    }
//
//    @GetMapping("/login")
//    public Object login(HttpServletRequest request) throws IOException {
//        //先获取验证码
//        getCode();
//        String dataUrl = "https://5535393761-rrl.cp168.ws/login?type=1&account=sishi12&password=Qwqw12121&getCode=" + code;
//
//        String result = doGet(dataUrl).getResponseBodyAsString();
//        if (result.contains("用户协议")){
//            System.out.println("登录成功");
//        }else {
//            System.out.println("登录失败");
//        }
//        System.out.println(result);
//
//        return result;
//    }
//
//    private GetMethod doGet(String dataUrl) throws IOException {
//        HttpClient httpClient = new HttpClient();
//
//        GetMethod getMethod = new GetMethod(dataUrl);
//        httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
//        // 每次访问需授权的网址时需带上前面的 cookie 作为通行证
//        if (StringUtils.isNotBlank(cookie)) {
//            getMethod.setRequestHeader("cookie", cookie);
//        }
//        httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
//        int statusCode = httpClient.executeMethod(getMethod);
////        System.out.println(getMethod.getResponseBodyAsString().toString());
//        // 获取Cookie
//            Cookie[] cookies = httpClient.getState().getCookies();
//            StringBuffer tmpcookies = new StringBuffer();
//            for (Cookie c : cookies) {
//                tmpcookies.append(c.toString() + ";");
//                System.out.println("cookies = "+c.toString());
//            }
//            if (StringUtils.isNotBlank(tmpcookies.toString())){
//                cookie = tmpcookies.toString();
//            }
//            return getMethod;
//
//
//    }
//
//
//
//    public void getCode() throws IOException {
//
//               // 登陆 Url
//        String loginUrl = "https://5535393761-rrl.cp168.ws/getCode?_=" + System.currentTimeMillis();
//
//        byte[] data = doGet(loginUrl).getResponseBody();
//
//        // 初始化一个AipOcr
//        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
//
//        // 可选：设置网络连接参数
//        client.setConnectionTimeoutInMillis(2000);
//        client.setSocketTimeoutInMillis(60000);
//
//
//        // 传入可选参数调用接口
//        HashMap<String, String> options = new HashMap<String, String>();
//        options.put("language_type", "CHN_ENG");
//        options.put("detect_direction", "true");
//        options.put("detect_language", "true");
//        options.put("probability", "true");
//
//
//
//        // 调用接口
//        JSONObject res = client.basicGeneral(data, options);
//        String wordsResult = res.toString();
//        if (StringUtils.isNotBlank(wordsResult)){
//            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(wordsResult);
//            JSONArray words_result = jsonObject.getJSONArray("words_result");
//            String index = words_result.get(0).toString();
//            com.alibaba.fastjson.JSONObject result = JSON.parseObject(index);
//            code = result.getString("words");
//            System.out.println("getCode:" +code);
//        }
//    }
//
//
//}
